# py main script
#
# - note the '##' lines that start a doxygen documentation block.

from sys import *
from google.appengine.ext import db


## this shall become 'pyspiel/model/Users.py'
# and would be imported from here by 'import model.User'
class Users(db.Model):
    ## connection to the google-user
    google_user = db.UserProperty()
    ## any name the user wants to choose for himself (to prevent spam mail etc)
    alias = db.StringProperty()
    ## last login date
    last_login = db.DateTimeProperty(auto_now=True)
    ## god(95) > pro(70) > regular(50) > honor(40) > tester(30) > watcher(20) > tentative(10) > guest(0)
    member_state = db.IntegerProperty()

    ## print a table header for simple dumping elements
    def th():
        print "<tr><th>Google</th><th>Alias</th><th>last</th><th>state</th>"
    th = staticmethod(th)

    ## dump element in table
    def tr(self):
        print "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" % (
            self.google_user, self.alias, self.last_login, self.member_state)


def main():
    print "context-type: text/html"
    print
    print "<html><body>"
    print "<table border=1>"
    print "<h1>Users</h1>"
    Users.th()
    for user in Users.all() or []:
        print user.tr()
    print "</table>"
    print "</body></html>"

if __name__ == "__main__":
    main()
